package com.example.demo.smartLamp.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.demo.smartLamp.entity.Environment;
import com.example.demo.smartLamp.entity.User;
import com.example.demo.smartLamp.entity.request.GetAllEnvironmentRequest;
import com.example.demo.smartLamp.entity.response.GetAllEnvironmentResponse;
import com.example.demo.smartLamp.mapper.EnvironmentMapper;
import com.example.demo.smartLamp.mapper.UserMapper;
import com.example.demo.smartLamp.service.IEnvironmentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 祁荣博 胡绍宇
 * @since 2022-07-23
 */
@Service
public class EnvironmentServiceImpl extends ServiceImpl<EnvironmentMapper, Environment> implements IEnvironmentService {

    @Resource
    UserMapper userMapper;
    @Resource
    EnvironmentMapper environmentMapper;

    @Override
    public GetAllEnvironmentResponse getAllEnInfo() {
//        Environment environment = new Environment();
//        environment = environmentMapper.selectOne(
//                Wrappers.lambdaQuery(Environment.class)
//                        .eq(Environment::getEnId, "1")
//        );

        List<Environment> eList= new ArrayList<Environment>();
//        eList = environmentMapper.selectList(Wrappers.lambdaQuery(Environment.class).orderByDesc(Environment::getEnTime));
        eList = environmentMapper.getEnvironmentList();
        if(eList.size()==0)
            return null;
        Environment environment = eList.get(0);

        GetAllEnvironmentResponse getAllEnvironmentResponse = new GetAllEnvironmentResponse();
        getAllEnvironmentResponse.setEnHumidity(environment.getEnHumidity());
        getAllEnvironmentResponse.setEnNoise(environment.getEnNoise());
        getAllEnvironmentResponse.setEnPm10(environment.getEnPm10());
        getAllEnvironmentResponse.setEnPm25(environment.getEnPm25());
        getAllEnvironmentResponse.setEnPressure(environment.getEnPressure());
        getAllEnvironmentResponse.setEnTemperature(environment.getEnTemperature());
        getAllEnvironmentResponse.setEnTime(environment.getEnTime());
        getAllEnvironmentResponse.setEnWindSpeed(environment.getEnWindSpeed());
        getAllEnvironmentResponse.setEnWindDirection(environment.getEnWindDirection());
        getAllEnvironmentResponse.setEq1Voltage(environment.getEq1Voltage());
        getAllEnvironmentResponse.setEq1Current(environment.getEq1Current());
        getAllEnvironmentResponse.setEq1Electricity(environment.getEq1Electricity());
        getAllEnvironmentResponse.setIlluminance(environment.getIlluminance());
        return getAllEnvironmentResponse;
    }

}
